//
//  ZJKUserAccount.swift
//  MicroBlog
//
//  Created by VAD on 16/4/19.
//  Copyright © 2016年 朱江坤. All rights reserved.
//

import UIKit

class ZJKUserAccount: NSObject,NSCoding {
    
    var uid: String?
    // 过期时间

    var expires_in: NSTimeInterval = 0{
        didSet{
            expiresDate = NSDate(timeIntervalSinceNow: expires_in)
        }
    }
    //    var expires_in: String?  --> 会崩溃
    var expiresDate: NSDate?
    
    var access_token: String?
    
    var remind_in: String?
    
    var name: String?
    // 用户头像地址（大图），180×180像素
    var avatar_large: String?
    
    init(dict: [String: AnyObject]) {
        super.init()
        setValuesForKeysWithDictionary(dict)
    }
    
    required init?(coder decoder: NSCoder) {
        uid = decoder.decodeObjectForKey("uid") as? String
        expires_in = decoder.decodeDoubleForKey("expires_in")
        access_token = decoder.decodeObjectForKey("access_token") as? String
        remind_in = decoder.decodeObjectForKey("remind_in") as? String
        name = decoder.decodeObjectForKey("name") as? String
        avatar_large = decoder.decodeObjectForKey("avatar_large") as? String
        // 解档过期时间
        expiresDate = decoder.decodeObjectForKey("expiresDate") as? NSDate
    }
    
    func encodeWithCoder(encoder: NSCoder) {
        encoder.encodeObject(uid, forKey: "uid")
        encoder.encodeDouble(expires_in, forKey: "expires_in")
        encoder.encodeObject(access_token, forKey: "access_token")
        encoder.encodeObject(remind_in, forKey: "remind_in")
        encoder.encodeObject(name, forKey: "name")
        encoder.encodeObject(avatar_large, forKey: "avatar_large")
        // 将过期时间也要归档
        encoder.encodeObject(expiresDate, forKey: "expiresDate")
    }

}
